#include <stdio.h>
#include "sequential_stack.h"

void SeqStackDemo(void)
{
    SeqStack_t stack;
    BrowserData_t temp;

    // 初始化栈
    SeqStackInit(&stack);

    // 准备3个数据
    BrowserData_t d1 = { "OpenAI",  "2025-07-15 10:00", "https://openai.com" };
    BrowserData_t d2 = { "Baidu",   "2025-07-15 10:10", "https://baidu.com" };
    BrowserData_t d3 = { "Google",  "2025-07-15 10:20", "https://google.com" };

    // 入栈操作
    SeqStackPush(&stack, &d1);
    SeqStackPush(&stack, &d2);
    SeqStackPush(&stack, &d3);

    printf("当前栈顶元素为：\n");
    if (SeqStackGetTop(&stack, &temp) == SEQ_STACK_SUCCESS) {
        printf("Title: %s\nTime: %s\nURL: %s\n\n", temp.title, temp.timestamp, temp.url);
    }

    // 出栈操作并打印
    printf("开始出栈:\n");
    while (!SeqStackIsEmpty(&stack)) {
        if (SeqStackPop(&stack, &temp) == SEQ_STACK_SUCCESS) {
            printf("出栈 -> Title: %s, Time: %s, URL: %s\n",
                   temp.title, temp.timestamp, temp.url);
        }
    }

    // 检查栈是否为空
    if (SeqStackIsEmpty(&stack)) {
        printf("\n栈现在为空。\n");
    }

}
